I have a datageidview which supposed to color the rows with contains specific value
private void dataGridView2_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
foreach (DataGridViewRow myrow in dataGridView2.Rows)
{
if (e.RowIndex != -1)
{
if (myrow.Cells[7].Value.ToString() == "Error")
{
myrow.DefaultCellStyle.BackColor = Color.Red;
}
else if (myrow.Cells[7].Value.ToString() == "NoError")
{
myrow.DefaultCellStyle.BackColor = Color.Green;
}
}
}
}
but i have a problem when the first row contains this value all the rows is colored with it's color
any help ??
Pravesh Singh
18-Aug-2014The CellFormatting event is sent for all visible cells in the grid. You may have better luck using the data given in the event to change the color.